#ifndef _SYN_VOICE_H
#define _SYN_VOICE_H

#include "syncommon.h"
#include "synoscillator.h"
#include "synfx.h"

namespace Synth {

class Channel;

class Voice {
	Channel *channel;
	int note;
	int vel;
	Oscillator osc[3];
	Envelope volAmp;
	Envelope env2;
	SVFFilter lfilt;
	SVFFilter rfilt;
	LFO lfo[2];

	float curNote;
	float targetNote;
	float noteDelta;

	bool playFlag;
public:
	Voice();
	int group;
	int timeStamp;
	void Play(Channel *chan, int note, int vel, bool bend);
	void Stop();
	void StopHard();

	void RenderAdd(Block lbuffer, Block rbuffer);
	void ResetVoiceParameters();
	void RunSlowThings();

	int GetPlayingNote() const {if (IsPlaying()) return note; else return 0;}
	float GetAmp() const {
		return volAmp.GetValue();
	}
	int GetScore(Channel *chan, int cnote) const {  // priority score
		int val = (int)((1 - volAmp.GetValue())*255);
		int score = (chan == channel && cnote == note) << 24;
		if ((volAmp.phase == EP_DEAD)) score += (int)(val << 16);
		if (chan == channel) score += val << 8;
		score += val;
		return score;
	}
	bool IsPlaying() const {return channel != 0;}
	const Channel *GetChannel() const {return channel;}
};

}  // namespace

#endif